<?php

use yii\helpers\Html;
//use yii\grid\GridView;
use kartik\grid\GridView;


$this->title = '取消人员列表';
$this->params['breadcrumbs'][] = $this->title;

?>

<?=  yii\web\View::registerCssFile("/css/magic-check.css",['depends' => 'app\assets\AppAsset']) ?>

<div class="customer-index">

    <h2 class="page-header"><?= Html::encode($this->title) ?>
        <p class="pull-right"></p>
    </h2>
    

    <p>
        <?php  echo $this->render('_search_cancel', ['model' => $searchModel]); ?>
    </p>

    <div class="page-header" style="height: 40px;">

        <input type="hidden" value="<?php echo Yii::$app->getRequest()->getCsrfToken(); ?>" name="_csrf" id="_csrf" />

        <input class="magic-checkbox room_all" type="checkbox" id="room_all"  ><label for="room_all"  style="display:inline;" title="选择所有该房间">全选</label>

        <p class="pull-right" style="display:inline;">
            <button class="btn btn-success confirm">确定取消</button>
        </p>   
    </div>

    <?= GridView::widget([
        'dataProvider' => $dataProvider,
        //'filterModel' => $searchModel,
        'layout'  =>  "{items}\n{pager}",
        //'pjax'=>true,
        //'striped'=>true,
        //'hover'=>true,
        'columns' => [
            //['class' => 'yii\grid\SerialColumn'],
            // ['class'=>'kartik\grid\SerialColumn'],
            //'id',
            //'room_use_id',
            [
                'label' => '',
                'format'=>'raw',
                 'value' => function($model){
                       $str = '<input class="magic-checkbox room-magic" type="checkbox" id="room_'.$model->id.'" data-id="'.$model->id.'"><label for="room_'.$model->id.'"  style="display:inline;" title="选择该房间"></label>';
                       return $str;
                 },
            ],
            [
                'label' => '房间名称',
                'format'=>'raw',
                'attribute' => 'room_use_id',
                'value'=>function ($model) {
                    $room =  $model->roomUse->room->name.' '.$model->roomUse->room->code. ' '.$model->roomUse->num.'人间';
                    return $room;
                },
            ],
            [
                'label' => '姓名',
                'format'=>'raw',
                'value'=>function ($model) {
                    return $model->first_name.$model->last_name;
                },
            ],
            //'en_first_name',
            //'en_last_name',
            //'pinyin',
            //'gender',
            [
                'attribute' => 'gender',
                'filter' =>  Yii::$app->params['gender'],
                'value' => function ($model) {
                    return isset(Yii::$app->params['gender'][$model->gender])?Yii::$app->params['gender'][$model->gender]:'';
                },
                'format' => 'raw',
            ],
            'birthday',
            //'country',
            //'passport',
            //'passport_add',
            //'passport_date',
            //'passport_type',
            'phone',
            'remark',
            'group',
            'supply',
            //'status',
             [
                'attribute' => 'status',
                'filter' =>  Yii::$app->params['status'],
                'value' => function ($model) {
                    return Yii::$app->params['status'][$model->status];
                },
                'format' => 'raw',
            ],

            [
                'attribute' => 'updated_at',
                'label'=>'取消时间',
                'value' => function ($model) {
                    return date("Y年m月d日 H:i:s",strtotime($model->updated_at));
                },
                'format' => 'raw',
            ],

             [
                'attribute' => 'cancel',
                'filter' =>  Yii::$app->params['cancel'],
                'value' => function ($model) {
                    return Yii::$app->params['cancel'][$model->cancel];
                },
                'format' => 'raw',
            ],
            //'user_id',
            //'created_at',
            //'updated_at',

            [
                'label'=>'审核',
                'format'=>'raw',
                'value' => function($model){
                   
                    $url = sprintf("/cruise/customer/look?id=%d", $model->id);
                    $str = Html::a('审核',$url,['title' => '审核','class'=>'btn btn-success btn-xs','target'=>'_blank']);
                        
                    return $str;
                }
            ],
        ],
    ]); ?>
</div>

<?php app\components\JsBlock::begin() ?>
<script type="text/javascript">

$(".confirm").click(function(){
    var msg = "您真的确定要取消吗?"; 
     if (confirm(msg)==true){ 
       
     }else{ 
       return false; 
     } 
    var all_select_id = new Array();
    $(".room-magic").each(function(){
        var checked = $(this).is(':checked');
        if(checked){
            all_select_id.push($(this).data('id'));
        }
    });

    if(all_select_id.length <= 0){
        alert("没有选择人员");
        return false;
    }
    var _csrf = $("#_csrf").val();

    $.ajax({
       type: "POST",
       async:false, 
       url: "/cruise/customer/status",
       data: {"_csrf":_csrf,"people_id":all_select_id},
       success: function(msg){
           if(msg == 0){
               alert("确定取消失败");
               window.location.reload();
           }else if(msg == 1){
               alert("确定取消成功");
               window.location.reload();
           }

       }
    });

});

$(".room_all").click(function(){
    var checked = $(this).is(':checked');
    if(checked){
        $(".room-magic").each(function(){
        
            $(this).prop("checked",true);  // attr 第三次会失败
        });
    }else{
        $(".room-magic").each(function(){
            $(this).prop("checked", false);
        });
    }
    
});


</script>
<?php app\components\JsBlock::end() ?>   
